from sys import exc_info
from MU_Mod import *

wins = []
# 定义函数用于获取指定标题窗口的句柄和位置大小信息

for title in ["龙鳞", "永恒之巅"]:
	hwnd = windll.user32.FindWindowW(None, title)
	if hwnd:
		rect = RECT()
		try:
			windll.user32.GetWindowRect(hwnd, byref(rect))
		except:
			pass
		if title == "永恒之巅":
			wins +=[{"rect":rect, "title":title, "mode":"boss", "coords":[(575,361),(504,221)], "last_coord":[0.6, 0.51], "tsleep":[15,2], "line":3, "turn":0}] # 遗址1 两Boss
			#wins +=[{"rect":rect, "title":title,"coords":[(685,277),(520,285),(326,396)], "last_coord":[0.6, 0.51], "line":4, "turn":0}] #废墟2 三个Boss
		else:
			wins +=[{"rect":rect, "title":title, "mode":"king", "bound":[1,2,1,0], "coords":[(575,361), (552,316), (587,267), (504,221)], "last_coord":[0.6, 0.51], "tsleep":[6,3.5,7.5], "line":3, "turn":0}] # 遗址1: B1,K1,K2,B2

#nextline_img = cv2.imread('MU_nextline.png')
while True:
	try:
		for window in wins:
			rect = window["rect"]
			loc_click(rect, coords_spec["active"]) # 激活窗口
			title = window["title"]

			if title == "永恒之巅" or (title == "龙鳞" and localtime(time()).tm_hour < 9):	# 刷boos模式
				if window["mode"] == "king":
					window["coords"] = [(575,361),(504,221)]
					window["tsleep"] = [15,2]
					window["mode"] = "boss"
				diagClose(rect, loc_capture(rect, 1440), 'yivi1') # 检测界面异常
				gamePlay(rect, window, 1440) # 最后一个1440为主屏横向分辨率,用于第二屏幕的情况, 主屏情况省略即可
			elif title == "龙鳞":	# 刷黄金, 不切线, 来回刷
				if window["mode"] == "boss":
					window["coords"] = [(552,316), (587,267)]
					window["tsleep"] = [4,4]
					window["mode"] = "king"
				diagClose(rect, loc_capture(rect, 1440), 'yivi1') # 检测打开的对话框
				gamePlay(rect, window, 1440)
			else: # 会员领地
				window["mode"] = "vip"
				diagClose(rect, loc_capture(rect, 1440), 'vip') # 检测打开的对话框
				gamePlay(rect, window, 1440)
	except:
		print("Unexpected error:", exc_info()[0:2])
		pass
	sleep(2)